package utils;


import logic.Destination;
import logic.Product;
import logic.User;

/**
 * Clase para calcular el ratio del producto en base al producto, 
 * destino y usuario
 * @author Nando
 *TODO Mirar votos de voluntario
 */
public class CalculateRatio {
	
		
	public void calculateProduct(Product p,User u, Destination d){
		double ratio = 0;
		System.out.print("Hola");
		System.out.print(u.getId() + "producto:" + p.getId());
		
		if( p!=null ){
			System.out.print("Hola entra");
			Integer votesb = u.getBuyerVotes();
			if(votesb == null)
				votesb = 0;
			Integer votesd= u.getDonorVotes();
				votesd = 0;
			int donate = u.getAmountDonate();
			int buyed = u.getAmountDonateBuyed();
			float money = u.getMoneyRaised();
			int prior = d.getPriority();
			if (prior>0 && money>0){
				ratio = ratio + 0.2*prior + 0.1*money;
			}	
			if (donate>0 && buyed>0 ){
				ratio = ratio + 0.8*(donate/buyed);
			}
			if(votesb>0 && votesd>0){
				ratio = ratio + 0.15*u.getBuyerVotes()+ 0.1*u.getDonorVotes();
			}
			p.setRatio(ratio);
			if(ratio>0.8){
				p.setActive(true);
			}else if(ratio>0.1){
					p.setActive(false);
				}else{
					p = null;
				}
		}
	}
}
